﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <link href="/Static/demo.css" rel="stylesheet" type="text/css" />
    <script src="/Static/boot.js" type="text/javascript"></script>
    <link href="/Static/miniui/themes/blue/skin.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div class="mini-toolbar" style="border-bottom:0;padding:0px;">
        <table style="width:100%;">
            <tr>
                <td style="width:100%;">
                    <a class="mini-button" iconcls="icon-add" onclick="AddMaintenance()" plain="true">增加</a>
                    <span class="separator"></span>
                    <a class="mini-button" iconcls="icon-edit" onclick="EditMaintenance()" plain="true">编辑</a>
                    <span class="separator"></span>
                    <a class="mini-button" iconcls="icon-remove" onclick="removeMaintenance()">删除</a>
                    <span class="separator"></span>
                    <a class="mini-button" iconcls="icon-reload" onclick="reloadData()" plain="true">刷新</a>
                    <input name="OrderID" class="mini-hidden" />
                </td>
            </tr>
        </table>
    </div>
    <div id="datagrid1" class="mini-datagrid" style="width: 100%; height: 93%;" url="/Ajax/AjaxService.aspx?method=GetMaintenance" multiselect="true" onrowdblclick="EditMaintenance"
         idfield="ID" sizelist="[5,10,20,50]" pagesize="10" ondrawcell="onDrawCell">
        <div property="columns">
            <div type="checkcolumn">
            </div>
            <div type="indexcolumn">
            </div>
            <div field="MaintenanceStatus" width="100" headeralign="center" allowsort="true">
                MaintenanceStatus
            </div>
            <div field="MaintPointGetProductTime" width="100" headeralign="center" dateformat="yyyy-MM-dd" allowsort="true">
                MaintPointGetProductTime
            </div>
            <div field="MaintenanceStartTime" width="100" headeralign="center" dateformat="yyyy-MM-dd" allowsort="true">
                MaintenanceStartTime
            </div>
            <div field="MaintenanceEndTime" width="100" align="center" headeralign="center" dateformat="yyyy-MM-dd">
                MaintenanceEndTime
            </div>
            <div field="MaintPointSendProductTime" width="100" allowsort="true" dateformat="yyyy-MM-dd">
                MaintPointSendProductTime
            </div>
            <div field="UserGetProductTime" width="100" allowsort="true" dateformat="yyyy-MM-dd">
                UserGetProductTime
            </div>
            <div field="UserExpressType" width="100" headeralign="center" allowsort="true">
                UserExpressType
            </div>
            <div field="UserExpressAmount" width="100" headeralign="center" allowsort="true" dateformat="yyyy-MM-dd">
                UserExpressAmount
            </div>
            <div field="MaintenanceNO" width="100" headeralign="center" allowsort="true">
                MaintenanceNO
            </div>
            <div field="Remark" width="100" headeralign="center" allowsort="true">
                Remark
            </div>
        </div>
    </div>
    <script type="text/javascript">
        mini.parse();
        var grid = mini.get("datagrid1");
        //grid.sortBy("ID", "DESC");
        //grid.load();

        function reloadData() {
            grid.sortBy("ID", "DESC");
            grid.load({ OrderID: mini.getbyName("OrderID").getValue() });
        }
        /**加载数据*********************************************************************/

        function SetData(data) {
            //跨页面传递的数据对象，克隆后才可以安全使用
            data = mini.clone(data);
            //mini.alert(data.OrderID);
            
            mini.getbyName("OrderID").setValue(data.OrderID);
            grid.sortBy("ID", "DESC");
            grid.load({ OrderID: data.OrderID });
        }

        function removeMaintenance() {
            var rows = grid.getSelecteds();
            if (rows.length > 0) {
                if (confirm("确定删除选中记录？")) {
                    var ids = [];
                    for (var i = 0, l = rows.length; i < l; i++) {
                        var r = rows[i];
                        ids.push(r.ID);
                    }
                    var id = ids.join(',');
                    //alert(id);
                    grid.loading("操作中，请稍后......");
                    $.ajax({
                        url: "/Ajax/AjaxService.aspx?method=DeleteMaintenance",
                        data: {
                            ids: id
                        },
                        success: function (text) {
                            // mini.alert("操作成功!");
                            grid.reload();
                        },
                        error: function () {
                        }
                    });
                }
            } else {
                mini.alert("请选中一条记录");
            }
        }
        function EditMaintenance() {
            var row = grid.getSelected();
            if (row) {
                mini.open({
                    url: bootPATH + "../Ali/MaintenanceEdit.html",
                    title: "编辑",
                    width: 900,
                    height: 600,
                    onload: function () {
                        var iframe = this.getIFrameEl();
                        var data = { action: "Update", ID: row.ID };
                        iframe.contentWindow.SetData(data);
                    },
                    ondestroy: function (action) {
                        grid.reload();
                    }
                });

            } else {
                alert("请选中一条记录");
            }
        }
        /**新增*********************************************************************/
        function AddMaintenance() {
            mini.open({
                url: bootPATH + "../Ali/MaintenanceEdit.html",
                title: "新增", width: 900, height: 600,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { action: "Insert", OrderID: mini.getbyName("OrderID").getValue() };
                    iframe.contentWindow.SetData(data);
                },
                ondestroy: function (action) {
                    grid.reload();
                }
            });
        }
        function onDrawCell(e) {
            var column = e.column,
                field = e.field,
                value = e.value,
                node = e.record;
            if (field == "UserExpressType") {
                switch(node.UserExpressType) {
                    case 1:
                        e.cellHtml = "自行到店";
                        break;
                    case 2:
                        e.cellHtml = "快递";
                        break;
                    default:
                        e.cellHtml = "";
                        break;
                }
            }
            if (field == "MaintenanceStatus") {
                switch (node.MaintenanceStatus) {
                    case 1:
                        e.cellHtml = "待维修";
                        break;
                    case 2:
                        e.cellHtml = "维修中";
                        break;
                    case 3:
                        e.cellHtml = "已维修";
                        break;
                    default:
                        e.cellHtml = "";
                        break;
                }
            }
        }
    </script>
</body>
</html>
